<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="utf-8">
<title>用户注册</title>
<link rel="shortcut icon" href="static/image/logo01.ico"/>
<link href="static/easyui/themes/default/easyui.css" rel="stylesheet" />
<link href="static/easyui/themes/icon.css" rel="stylesheet" />
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="static/easyui-lang-zh_CN.js"></script>
</head>
<body>
<div style="margin: 20px 0;"></div>
	<div class="easyui-panel" title="注册" style="width: 400px">
		<div style="padding: 10px 60px 20px 60px">
			<form id="loginForm">
				<table>
					<tr>
						<td>用户名：</td>
						<td><input class="easyui-textbox" type="text" id="username"
							name="username"></input></td>
					</tr>
					<tr>
						<td>密码：</td>
						<td><input class="easyui-passwordbox" type="password"
							id="password" name="password"></input>
							
						</td>
					</tr>
					<tr>
						<td>确认密码：</td>
						<td><input class="easyui-passwordbox" type="password" id="checkPassword" name="checkPassword"></input></td>
					</tr>
					<tr>
						<td>年龄：</td>
						<td><input class="easyui-numberbox" type="text" id="age" data-options="min:0,max:100" name="age"></input></td>
					</tr>
					<tr>
						<td>手机号：</td>
						<td><input class="easyui-textbox" type="text" id="phone" name="phone"></input></td>
					</tr>
					<tr>
						<td>住址：</td>
						<td><input class="easyui-textbox" type="text" id="address" name="address"></input></td>
					</tr>
					<tr>
						<td>性别：</td>
						<td>
							<input type="radio" name="gender" checked value="男" />男
                			<input type="radio" name="gender" value="女" />女
						</td>
					</tr>
					<tr>
						<td>邮箱：</td>
						<td><input class="easyui-textbox" type="text" id="email" name="email"></input></td>
					</tr>
					<tr>
						<td>姓名：</td>
						<td><input class="easyui-textbox" type="text" id="realname" name="realname"></input></td>
					</tr>
				</table>
			</form>
			<div style="text-align: center; padding: 5px">
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-redo'" onclick="toLogin()">返回</a>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="submitForm()">提交</a>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" onclick="clearForm()">重置</a>
			</div>
			<div>
				<label style="color:red">密码6-10个字符，数字和字母组成</label>
			</div>
		</div>
	</div>

	<script>
		var passwordReg =  /^[A-Za-z0-9]{6,10}$/;
		var phoneReg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
		var emailReg = /^[A-Za-zd0-9]+([-_.][A-Za-zd]+)*@([A-Za-zd]+[-.])+[A-Za-zd]{2,5}$/;
		$(function() {
		})
		function toLogin() {
			window.location.href='login.jsp';
		}
		// 点击注册
		function submitForm() {
			var username = $("#username").val();
			var password = $("#password").passwordbox('getValue');
			var checkPassword = $("#checkPassword").passwordbox('getValue');
			var age = $("#age").numberbox('getValue');
			var phone = $("#phone").val();
			var address = $("#address").val();
			var gender = $("input[name='gender']:checked").val();
			var email = $("#email").val();
			var realname = $("#realname").val();
			
			if (username == "" || username == null) {
				$.messager.alert('提示', '请输入正确的用户名', 'error');
				return;
			}
			
			if (!passwordReg.test(password)) {
				$.messager.alert('提示', '请按照格式输入密码', 'error');
				return;
			}
			
			if (password != checkPassword) {
				$.messager.alert('提示', '两次密码不一致', 'error');
				return;
			}
			if(!phoneReg.test(phone)) {
				$.messager.alert('提示', '请输入正确的手机号', 'error');
				return;
			}
			if(!emailReg.test(email)) {
				$.messager.alert('提示', '请输入正确的邮箱', 'error');
				return;
			}
			
			$.ajax({
				type : "post",
				url : "register",
				data : {
					username : username,
					password : password,
					age: age,
					phone: phone,
					address: address,
					gender: gender,
					email: email,
					realname: realname
				},
				success : function(data) {
					if (data.code == 0) {
						$.messager.alert('提示信息',data.message,"info",function() {
								document.location.href="login.jsp"
						});
						
					} else {
						$.messager.alert('提示信息', data.message, "error");
					}
				}
			});

		}
		// 清空
		function clearForm() {
			$("#username").textbox('reset');
			$("#password").passwordbox('reset');
			$("#checkPassword").passwordbox('reset');
			$("#age").numberbox('reset');
			$("#phone").textbox('reset');
			$("#address").textbox('reset');
			$("#email").textbox('reset');
			$("#realname").textbox('reset');
		}
	</script>
</body>
</html>